/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IngresoPostre.java
 *
 * Created on 14-abr-2012, 23:36:46
 */
package gui;

import java.util.ListIterator;
import javax.swing.JOptionPane;
import modelo.Alimento;
import modelo.Cliente;
import modelo.Comida;
import modelo.Restaurante;

/**
 *
 * @author Lenovo
 */
public class IngresoPostre extends javax.swing.JFrame {

    /**
     * Creates new form IngresoPostre
     */
    private Restaurante restaurante;
    private int mesaPedido;
    private int sillaPedido;
    VentanaPrincipal v;

    public IngresoPostre(Restaurante restaurante, int mesaPedido, int sillaPedido) {
        initComponents();
        this.restaurante = restaurante;
        this.mesaPedido = mesaPedido;
        this.sillaPedido = sillaPedido;
        this.setLocationRelativeTo(null);
        cargarComboPostres();

    }

    /**
     * carga las comodas de tipo Comida en el combo
     */
    public void cargarComboPostres() {
        jCBPostre.removeAllItems();
        ListIterator<Alimento> iterator = restaurante.getMenu().listIterator();
        while (iterator.hasNext()) {
            Alimento a = iterator.next();
            if (a instanceof Comida) {
                Comida c = (Comida) a;
                if (c.getTipo().equals(Comida.TIPO_POSTRE)) {
                    jCBPostre.addItem(c.getNombre());
                }
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPPostre = new javax.swing.JPanel();
        jLImgPostre = new javax.swing.JLabel();
        jCBPostre = new javax.swing.JComboBox();
        jLPostre = new javax.swing.JLabel();
        jLCantPostre = new javax.swing.JLabel();
        jSCantPostre = new javax.swing.JSpinner();
        jBCancelarAgregarPostre = new javax.swing.JButton();
        jBAgregarPostre = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Restaurante \"Con Sabor\" - Adicionar Postre");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPPostre.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Postre", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(204, 0, 102))); // NOI18N

        jLImgPostre.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/postre.jpg"))); // NOI18N
        jLImgPostre.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jCBPostre.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jCBPostre.setForeground(new java.awt.Color(153, 0, 51));
        jCBPostre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una opción" }));

        jLPostre.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLPostre.setForeground(new java.awt.Color(153, 0, 51));
        jLPostre.setText("Postre a agregar:");

        jLCantPostre.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLCantPostre.setForeground(new java.awt.Color(153, 0, 51));
        jLCantPostre.setText("Cantidad para este pedido:");

        javax.swing.GroupLayout jPPostreLayout = new javax.swing.GroupLayout(jPPostre);
        jPPostre.setLayout(jPPostreLayout);
        jPPostreLayout.setHorizontalGroup(
            jPPostreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPPostreLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLImgPostre)
                .addGap(18, 18, 18)
                .addGroup(jPPostreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPPostreLayout.createSequentialGroup()
                        .addComponent(jLPostre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCBPostre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPPostreLayout.createSequentialGroup()
                        .addComponent(jLCantPostre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jSCantPostre, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPPostreLayout.setVerticalGroup(
            jPPostreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPPostreLayout.createSequentialGroup()
                .addGroup(jPPostreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPPostreLayout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addGroup(jPPostreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLPostre)
                            .addComponent(jCBPostre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(27, 27, 27)
                        .addGroup(jPPostreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLCantPostre)
                            .addComponent(jSCantPostre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLImgPostre, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jBCancelarAgregarPostre.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBCancelarAgregarPostre.setForeground(new java.awt.Color(204, 0, 102));
        jBCancelarAgregarPostre.setText("CANCELAR");

        jBAgregarPostre.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBAgregarPostre.setForeground(new java.awt.Color(204, 0, 102));
        jBAgregarPostre.setText("AGREGAR POSTRE");
        jBAgregarPostre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAgregarPostreActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPPostre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(103, 103, 103)
                        .addComponent(jBAgregarPostre)
                        .addGap(69, 69, 69)
                        .addComponent(jBCancelarAgregarPostre)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPPostre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBAgregarPostre)
                    .addComponent(jBCancelarAgregarPostre))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBAgregarPostreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAgregarPostreActionPerformed
        String alimento = (String) jCBPostre.getSelectedItem();
        int cantidadPostre = (Integer) jSCantPostre.getValue();
        Alimento ali = restaurante.buscarAlimento(alimento);
        if (ali != null) {
            ali.setCantidad(cantidadPostre);
            Cliente c = restaurante.getClientes()[mesaPedido][sillaPedido];
            String msj = c.modificarPedido(ali, cantidadPostre);
            JOptionPane.showMessageDialog(null, msj);

        } else {
            JOptionPane.showMessageDialog(null, "Este alimento no esta disponible en el menu");
        }
    }//GEN-LAST:event_jBAgregarPostreActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        v.cargarConsumoActual();
    }//GEN-LAST:event_formWindowClosed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAgregarPostre;
    private javax.swing.JButton jBCancelarAgregarPostre;
    private javax.swing.JComboBox jCBPostre;
    private javax.swing.JLabel jLCantPostre;
    private javax.swing.JLabel jLImgPostre;
    private javax.swing.JLabel jLPostre;
    private javax.swing.JPanel jPPostre;
    private javax.swing.JSpinner jSCantPostre;
    // End of variables declaration//GEN-END:variables

}
